package math;

public class Vector3D {

    public double x;
    public double y;
    public double z;

    public double getX() {
	return x;
    }

    public String toString(){
	return "[" + x + "," + y + "," + z + "]";
    }
    
    public void setX( double x ) {
	this.x = x;
    }

    public double getY() {
	return y;
    }

    public void setY( double y ) {
	this.y = y;
    }

    public double getZ() {
	return z;
    }

    public void setZ( double z ) {
	this.z = z;
    }

    public Vector3D( double x , double y , double z ) {
	this.x = x;
	this.y = y;
	this.z = z;
    }

    public Vector3D() {
	x = 0;
	y = 0;
	z = 0;
    }

    public Vector3D add( Vector3D other ) {
	return new Vector3D( x + other.x , y + other.y , z + other.z );
    }

    public Vector3D minus( Vector3D other ) {
	return new Vector3D( x - other.x , y - other.y , z - other.z );
    }

    public Vector3D mult( Vector3D other ) {
	return new Vector3D( x * other.x , y * other.y , z * other.z );
    }

    public Vector3D div( Vector3D other ) {
	return new Vector3D( x / other.x , y / other.y , z / other.z );
    }

    public Vector3D add( double other ) {
	return new Vector3D( x + other , y + other , z + other );
    }

    public Vector3D minus( double other ) {
	return new Vector3D( x - other , y - other , z - other );
    }

    public Vector3D mult( double other ) {
	return new Vector3D( x * other , y * other , z * other );
    }

    public Vector3D div( double other ) {
	return new Vector3D( x / other , y / other , z / other );
    }

    public void Normalize() {
	double Norm = 1 / (Math.sqrt( (x) * (x) + (y) * (y) + (z) * (z) ));
	x *= Norm;
	y *= Norm;
	z *= Norm;
    }

    public double dot( Vector3D other ) {
	return (x * other.x) + (y * other.y) + (z * other.z);
    }

    public static double distance( Vector3D A , Vector3D B ) {
	return Math.sqrt( ((A.x - B.x) * (A.x - B.x)) + ((A.y - B.y) * (A.y - B.y)) + ((A.z - B.z) * (A.z - B.z)) );
    }

    // just for Vector3D colors
    public int toHex() {
	return (int) ((255 * x * 256 * 256) + (255 * y * 256) + (255 * z));
    }

    public static Vector3D randomVector() {
	Vector3D ret = new Vector3D( Math.random() , Math.random() , Math.random() );
	ret.Normalize();
	return ret;
    }
    
    public Vector3D clone() {
	Vector3D ret = new Vector3D(x,y,z);
	return ret;
    }

}
